window: stop stomping on resize-mode set by external API
authorCosimo Cecchi <cosimoc@gnome.org>
Mon, 14 Mar 2016 22:41:16 +0000 (15:41 -0700)
committerCosimo Cecchi <cosimoc@gnome.org>
Mon, 14 Mar 2016 23:10:15 +0000 (16:10 -0700)
commit c3dc0d80f1353ac66882ca3288ca7e9a13c47d6f fixed the behavior of
GtkContainer widgets requesting an IMMEDIATE resize-mode.

However, GtkWindow has been stomping on resize-mode during realize()
since commit addcc64b9cbb2fb1225080075ad3112a3d93d839. The combination
of factors that led to this not being a visible problem during all this
while is uncertain, but this now causes the Shell to continuously try to
relayout its ShellEmbeddedWindow (a GtkWindow subclass).

This commit separates the resize-mode as set internally by GtkWindow
from the one set with the external API, so that GtkWindow only changes
it when it had not been set before by the subclass.

https://bugzilla.gnome.org/show_bug.cgi?id=763650

gtk/gtkcontainer.c
gtk/gtkcontainerprivate.h
gtk/gtkwindow.c

index 5e6d54a39c33baf86fdf4fd3c3e022c55840fb32..44c6573796fc7630e4b0a2aa43dc5748028bad67 100644 (file)
@@ -287,6 +287,7 @@ struct _GtkContainerPrivate
   guint reallocate_redraws : 1;
   guint restyle_pending    : 1;
   guint resize_mode        : 2;
+  guint resize_mode_set    : 1;
   guint request_mode       : 2;
 };
 
@@ -1909,6 +1910,28 @@ gtk_container_remove (GtkContainer *container,
   g_object_unref (container);
 }
 
+static void
+gtk_container_real_set_resize_mode (GtkContainer  *container,
+                                    GtkResizeMode  resize_mode)
+{
+  GtkWidget *widget = GTK_WIDGET (container);
+  GtkContainerPrivate *priv = container->priv;
+
+  if (_gtk_widget_is_toplevel (widget) &&
+      resize_mode == GTK_RESIZE_PARENT)
+    {
+      resize_mode = GTK_RESIZE_QUEUE;
+    }
+
+  if (priv->resize_mode != resize_mode)
+    {
+      priv->resize_mode = resize_mode;
+
+      gtk_widget_queue_resize (widget);
+      g_object_notify_by_pspec (G_OBJECT (container), container_props[PROP_RESIZE_MODE]);
+    }
+}
+
 /**
  * gtk_container_set_resize_mode:
  * @container: a #GtkContainer
@@ -1929,26 +1952,26 @@ gtk_container_set_resize_mode (GtkContainer  *container,
                                GtkResizeMode  resize_mode)
 {
   GtkContainerPrivate *priv;
-  GtkWidget *widget = (GtkWidget *)container;
 
   g_return_if_fail (GTK_IS_CONTAINER (container));
   g_return_if_fail (resize_mode <= GTK_RESIZE_IMMEDIATE);
 
   priv = container->priv;
+  priv->resize_mode_set = TRUE;
 
-  if (_gtk_widget_is_toplevel (widget) &&
-      resize_mode == GTK_RESIZE_PARENT)
-    {
-      resize_mode = GTK_RESIZE_QUEUE;
-    }
+  gtk_container_real_set_resize_mode (container, resize_mode);
+}
 
-  if (priv->resize_mode != resize_mode)
-    {
-      priv->resize_mode = resize_mode;
+void
+gtk_container_set_default_resize_mode (GtkContainer *container,
+                                       GtkResizeMode resize_mode)
+{
+  GtkContainerPrivate *priv = container->priv;
 
-      gtk_widget_queue_resize (widget);
-      g_object_notify_by_pspec (G_OBJECT (container), container_props[PROP_RESIZE_MODE]);
-    }
+  if (priv->resize_mode_set)
+    return;
+
+  gtk_container_real_set_resize_mode (container, resize_mode);
 }
 
 /**
index 1961444f7c959cf9e8cfd03fac880de6f85d468f..7402a6676be4428a1f458df1c588df34d67a7a5c 100644 (file)
@@ -44,6 +44,8 @@ void      _gtk_container_set_border_width_set   (GtkContainer *container,
                                                  gboolean      border_width_set);
 void      gtk_container_get_children_clip       (GtkContainer  *container,
                                                  GtkAllocation *out_clip);
+void      gtk_container_set_default_resize_mode (GtkContainer *container,
+                                                 GtkResizeMode resize_mode);
 
 G_END_DECLS
 
index 3e8d321edb2a77cb40b70e10b40c87a02f878bb6..6b21e0bf238650885fb95c50744b624e4be243ec 100644 (file)
@@ -1637,9 +1637,7 @@ gtk_window_init (GtkWindow *window)
   _gtk_widget_set_is_toplevel (widget, TRUE);
   _gtk_widget_set_anchored (widget, TRUE);
 
-  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
-  gtk_container_set_resize_mode (GTK_CONTAINER (window), GTK_RESIZE_QUEUE);
-  G_GNUC_END_IGNORE_DEPRECATIONS;
+  gtk_container_set_default_resize_mode (GTK_CONTAINER (window), GTK_RESIZE_QUEUE);
 
   priv->title = NULL;
   priv->wmclass_name = g_strdup (g_get_prgname ());
@@ -7140,9 +7138,7 @@ gtk_window_realize (GtkWidget *widget)
 
   if (gtk_widget_get_parent_window (widget))
     {
-      G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
-      gtk_container_set_resize_mode (GTK_CONTAINER (widget), GTK_RESIZE_PARENT);
-      G_GNUC_END_IGNORE_DEPRECATIONS;
+      gtk_container_set_default_resize_mode (GTK_CONTAINER (widget), GTK_RESIZE_PARENT);
 
       attributes.x = allocation.x;
       attributes.y = allocation.y;
@@ -7166,9 +7162,7 @@ gtk_window_realize (GtkWidget *widget)
       return;
     }
 
-  G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
-  gtk_container_set_resize_mode (GTK_CONTAINER (window), GTK_RESIZE_QUEUE);
-  G_GNUC_END_IGNORE_DEPRECATIONS;
+  gtk_container_set_default_resize_mode (GTK_CONTAINER (window), GTK_RESIZE_QUEUE);
 
   /* ensure widget tree is properly size allocated */
   if (allocation.x == -1 &&